package com.solomon.travel.common.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.solomon.travel.common.mapper.ImageMapper;
import com.solomon.travel.common.po.Image;
import com.solomon.travel.common.po.ImageExample;
import com.solomon.travel.common.service.ImageService;
import com.solomon.travel.common.util.ConstantUtils;

@Service
public class ImageServiceImpl implements ImageService {

	@Override
	public int add(Image image) {
		return imageMapper.insertSelective(image);
	}

	@Resource
	private ImageMapper imageMapper;

	@Override
	public int deleteHotelImages(String hotelId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(hotelId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_HOTEL_INTRO);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteHotelDiningImages(String hotelId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(hotelId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_HOTEL_DINING);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteHotelMettingImages(String hotelId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(hotelId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_HOTEL_MEETING);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteRestImages(String objectId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(objectId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_REST_INTRO);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteMuneImages(String restId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(restId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_REST_MENU);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteGuideImages(String objectId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(objectId);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteScenicImages(String objectId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(objectId);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteMotorImages(String objectId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(objectId);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteProductImages(String shopId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(shopId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_SHOP_PRODUCT);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public int deleteShopImages(String objectId) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(objectId).andSubtypeEqualTo(ConstantUtils.IMAGE_SUBTYPE_SHOP_INTRO);
		return imageMapper.deleteByExample(example);
	}

	@Override
	public void delete_old_image(String organization_id) {
		ImageExample example = new ImageExample();
		example.createCriteria().andOrganizationIdEqualTo(organization_id);
		imageMapper.deleteByExample(example);
	}
}
